package gam.n1.cm;

import gam.n1.cm.i.*;
import gam.n1.conf.ConfManager;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;

public final class AcmTransfer {
    private final AcmHandler AreaCreateHandler;
    private final AcmHandler AreaRunHandler;
    private final AcmHandler AreaInitInsHandler;
    private final AcmHandler ConfigReloadHandler;
    private final AcmHandler AreaSaveHandler;
    public AcmTransfer(@NotNull Plugin plugin){
        AreaCreateHandler = new AreaCreateHandler(plugin);
        AreaRunHandler = new AreaRunHandler(plugin);
        AreaInitInsHandler = new AreaInitInsHandler(plugin);
        ConfigReloadHandler = new ConfigReloadHandler(plugin);
        AreaSaveHandler = new AreaSaveHandler(plugin);
    }
    public boolean hd(CommandSender executor, String[] args) throws Exception {
        boolean isPlayer = executor instanceof Player;
        String prefix = args[0];
        Player p = isPlayer? (Player) executor : null;
        switch (prefix){
            case "create":
                AreaCreateHandler.handle(p,reTurnNewArray(args));
                break;
            case "run":
                AreaRunHandler.handle(p,reTurnNewArray(args));
                break;
            case "ins":
                AreaInitInsHandler.handle(p,reTurnNewArray(args));
                break;
            case "save":
                AreaSaveHandler.handle(p,reTurnNewArray(args));
                break;
            case "reload":
                ConfigReloadHandler.handle(p,reTurnNewArray(args));
                break;
        }
        return false;
    }
    private static String[] reTurnNewArray(String[] args){
        String[] newArray = new String[args.length - 1];
        if (newArray.length > 0){
            System.arraycopy(args, 1, newArray, 0, args.length - 1);
            return newArray;
        }
        return null;
    }
}
